<template>
	<view>
		<view style="background-color: #FFFFFF;border-radius: 1.5em;height: 80%;
		padding: 100rpx;">
			<view>
				<view style="color: #808080;font-size: 30rpx;">手机号:</view>
				<u-input placeholder="请输入手机号" style="border-bottom: 1rpx #808080 solid;"
				type="number" maxlength="11" v-model="phone"></u-input>
			</view>
			<view style="margin-top: 50rpx;">
				<view style="color: #808080;font-size: 30rpx;">旧密码</view>
				<u-input placeholder="请输入旧密码" style="border-bottom: 1rpx #808080 solid;"
				type="password" v-model="password"></u-input>
			</view>
			<view style="margin-top: 50rpx;">
				<view style="color: #808080;font-size: 30rpx;">新密码</view>
				<u-input placeholder="请输入新密码" style="border-bottom: 1rpx #808080 solid;"
				type="password" v-model="password2"></u-input>
			</view>
			<view style="background-color: #fc6b2c; padding: 30rpx 30rpx;border-radius: 2em;
			font-weight: bold;color: #fffbef;width: 550rpx;text-align: center;margin: 50rpx 0;
			font-size: 29rpx;" @click="updateClick">
				<text>立即修改</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone:"",
				password:"",
				password2:""
			}
		},
		methods: {
			//
			async updateClick(){
				if(this.phone == "" || this.password == "" || this.password2 == ""){
					return uni.showToast({
						title:"不能为空",
						icon:"error"
					})
				}else if(this.phone.length != 11){
					return uni.showToast({
						title:"手机号填写不规范",
						icon:"error"
					})
				}
				const res=await this.$myRequst({
					url:"/user/get/phone?phone="+this.phone+"&password="+this.password
				})
				console.log(res.data)
				
				if(res.data.data == undefined){
					return uni.showToast({
						title:"无此账户信息",
						icon:"error"
					})
				}else{
					this.updateUserPassword()
				}
			},
			async updateUserPassword(){
				const res = await this.$myRequst({
					url:"/user/put",
					method:"PUT",
					data:{
						id:uni.getStorageSync("userId"),
						password:this.password2
					}
				})
				console.log(res)
				if(res.data.code == 200){
					uni.showToast({
						title:"修改成功",
						success: (res) => {
							uni.removeStorageSync("userId")
							setTimeout(()=>{
								uni.reLaunch({
									url:"../../logon/logon"
								})
							},1000)
						}
					})
				}
			}
		}
	}
</script>

<style>

</style>
